package net.neptech.service.impl;

import net.neptech.model.schedule.ScheSetting;
import net.neptech.model.schedule.ScheShift;
import net.neptech.repository.SchSettingRepository;
import net.neptech.service.ScheSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 谢辉
 * @Date 2025/8/13 16:49
 * @Description TODO
 **/
@Service
public class ScheSettingServiceImpl implements ScheSettingService {

    @Autowired
    SchSettingRepository scheSettingRepository;

    @Override
    public void addScheSetting(ScheSetting scheSetting) {
        scheSettingRepository.save(scheSetting);
    }

    @Override
    public void deleteScheSetting(Long setId) {
        //根据ID查到排班设置
        ScheSetting scheSetting = scheSettingRepository.findById(setId).orElseThrow(() -> new RuntimeException("未找到该数据"));
        //修改排班设置的状态
        scheSetting.setStatus(0);
        //保存修改后的排班设置
        scheSettingRepository.save(scheSetting);
    }

    @Override
    public void updateScheSetting(ScheSetting scheSetting) {
        scheSettingRepository.save(scheSetting);
    }

    @Override
    public Page<ScheSetting> getScheSettingByDeptId(Long deptId, Integer status, Integer size, Integer page) {
        Pageable pageable = PageRequest.of(page, size);
        return  scheSettingRepository.findByDeptIdAndStatus(deptId,1, pageable);
    }

    @Override
    public List<ScheSetting> getAllScheSettingByDeptId(Long deptId) {
       return scheSettingRepository.findByDeptIdAndStatus(deptId,1);
    }
}
